package com.belly.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Belly on 2019-11-23.
 */
public class Solution {
    public int[] findTwoSum(int[] src, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < src.length; i++) {
            int dis = target - src[i];
            if (map.containsKey(dis)) {
                return new int[] { i, map.get(dis) };
            }
            map.put(src[i], i);
        }
        return null;
    }

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        // 依次遍历两个链表
        ListNode head = new ListNode(0);

        ListNode pre = head;
        while (l1 != null && l2 != null) {
            if (l1.val <= l2.val) {
                pre.next = l1;
                l1 = l1.next;
            } else {
                pre.next = l2;
                l2 = l2.next;
            }
            pre = pre.next;
        }
        pre.next = l1 == null ? l2 : l1;

        return head.next;
    }

    class ListNode {
        int      val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public static void main(String[] args) {

    }
}
